def is_prime(num):
    for i in range(2, num):
        if num % i == 0:
            return False
    return True

prime_numbers = [x for x in range(10, 10000) if is_prime(x)]
digit_dict = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9,
}
user_input = input().split()

try:
    num_value = digit_dict[user_input[0]] * 100 + digit_dict[user_input[1]] * 10 + digit_dict[user_input[2]]
    min_diff = 1000
    closest_prime = 0
    for prime in prime_numbers:
        if abs(prime - num_value) < min_diff:
            min_diff = abs(prime - num_value)
            closest_prime = prime
    print(closest_prime)
except:
    print("Wrong input")
